{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}


{block name="content"}
<div class="t-art" style="margin-bottom:10px;">
	<a href="javascript:;" class="btn btn-blue" id="add-new"><i class="gicon-plus white"></i>添加等级</a>
</div>
<div class="tablesWrap">
	<!-- end tables-searchbox -->
	<table class="wxtables">
		<colgroup>
		<!-- <col width="10%"> -->
		<col width="35%">
		<col width="25%">
		<col width="15%">
		</colgroup>
		<thead>
			<tr>
				<!-- <td>编号</td> -->
				<td>等级名称</td>
				<td>所需经验</td>
				<td>操作</td>
			</tr>
		</thead>
		<tbody>
		{if $rank_list}
		{foreach from=$rank_list item=this key=k}
			<tr>
				<!-- <td>{$k + 1}</td> -->
				<td class="sort-name">{$this.rank_name}</td>
				<td class="sort-name">{$this.need_exp}</td>
				<td>
					<a href="javascript:;" onclick="editRank({$this.channel_rank_id}, this);" class="btn" title="修改"><i class="gicon-edit black"></i>编辑</a> 
					<!-- <a href="javascript:;" onclick="delSort({$this.article_sort_id}, this);" class="btn" title="删除"><i class="gicon-trash black"></i>删除</a>  -->
				</td>
			</tr>
		{/foreach}
		{else}
			<tr>
				<td colspan="5" class="center">暂无频道等级</td>
			</tr>
		{/if}
		</tbody>
	</table>
	<!-- end wxtables -->
	{if $rank_list}
	<div class="tables-btmctrl clearfix">
		<div class="fr">
			<div class="paginate">
				{$show}
			</div>
			<!-- end paginate -->
		</div>
	</div>
	{/if}
	<!-- end tables-btmctrl -->
</div>
<!-- end tablesWrap --> 
<form id="form1" style="display: none;">
	<div class="formitems inline">
		<label class="fi-name"><span class="colorRed">*</span>等级名称：</label>
		<div class="form-controls">
			<input type="text" name="rank_name" id="rank_name">
			<span class="fi-help-text"></span>
		</div>
	</div>
	<div class="formitems inline">
		<label class="fi-name">所需经验：</label>
		<div class="form-controls">
			<input type="text" name="need_exp" id="need_exp">
			<span class="fi-help-text"></span>
		</div>
	</div>
</form>
{/block} 

{block name="js"}
{literal}
<script type="text/javascript">
$(function(){
	$('.serial input').mouseenter(function(){
		$(this).css('cursor', 'pointer');
	})
	.click(function(){
		$(this).css('cursor', 'text');
		$(this).css('border-color', '#72b7cd');
	})
	.blur(function(){
		$(this).css('border-color', '#fff');
	});
	
	//添加标签
	$("#add-new").click(function() {
		var _html = $('#form1').clone().show();
		$.jPops.custom({
			title:"添加等级",
			content:_html,
			okBtnTxt:"确定",
			callback:function(r){
				acp.popFormStatus=false;//弹窗表单验证状态
				
				if(r){//点击确定按钮执行的事件
                    $.validator.setDefaults({
                        submitHandler: function() {
                            var param = $('#jpops #form1').serialize();
							$.ajax({
								url: '/AcpChannel/add_channel_rank',
								type:'post',
								data: param,
								dataType: 'json',
								success: function(data){
									alert(data.msg);
									if(data.code == 0){
										location.reload();
									}
								}
							});
                            acp.popFormStatus=true;//设置弹窗表单验证状态为通过
                        }
                    });
					
                    //表单验证规则
                    $("#jpops #form1").validate({
                        rules: {
                            rank_name: {
                                required: true
                            },
                            need_exp: {
                                required: true,
                                digits:true,
                            }
                        },
                        messages: {
                            rank_name: {
                                required: "请输入等级名称！"
                            },
                            need_exp: {
                                required: '请输入所需经验',
                                digits:'必须为整数',
                            }
                        },
                        errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                        success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                    });
					
					//模拟提交表单
					$("#jpops #form1").submit();
					
                    return acp.popFormStatus;//通过表单验证状态确定是否关闭窗口
                }
				return true;
			}
		});
	});
});
function editRank(_id, _this){
	
	var _html = $('#form1').clone().show();
	var _json = $('#edit-' + _id).val();
	if(_json == undefined){
		$.ajax({
			url: '/AcpChannel/get_channel',
			type:'post',
			data: {id: _id},
			dataType: 'json',
			async: false,
			success: function(data){
			//	console.log(data);
				$('#rank_name', _html).val(data.rank_name);
				$('#need_exp', _html).val(data.need_exp);
				$('#form1').append('<input type="hidden" value="' + encodeURIComponent(JSON.stringify(data)) + '" id="edit-' + data.channel_rank_id + '"  />');
			}
		});
	}
	else
	{
		_json = $.parseJSON(decodeURIComponent(_json));
		$('#rank_name', _html).val(_json.rank_name);
		$('#need_exp', _html).val(_json.need_exp);
	}
	
	$.jPops.custom({
		title:"修改等级",
		content:_html,
		okBtnTxt:"确定",
		callback:function(r){
			acp.popFormStatus=false;//弹窗表单验证状态
			
			if(r){//点击确定按钮执行的事件
				$.validator.setDefaults({
					submitHandler: function() {
						var param = $('#jpops #form1').serialize();
						param += '&id=' + _id;
						console.log(param)
						$.ajax({
							url: '/AcpChannel/edit_channel_rank',
							data: param,
							dataType: 'json',
							success: function(data){
							//	console.log(data);
								alert(data.msg);
								if(data.code == 0){
									location.reload();
								}
							}
						});
						acp.popFormStatus=true;//设置弹窗表单验证状态为通过
					}
				});
				
				//表单验证规则
				$("#jpops #form1").validate({
                        rules: {
                            rank_name: {
                                required: true
                            },
                            need_exp: {
                                required: true,
                                digits:true,
                            }
                        },
                        messages: {
                            rank_name: {
                                required: "请输入等级名称！"
                            },
                            need_exp: {
                                required: '请输入所需经验',
                                digits:'必须为整数',
                            }
                        },
                        errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
                        success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
                    });
				
				//模拟提交表单
				$("#jpops #form1").submit();
				
				return acp.popFormStatus;//通过表单验证状态确定是否关闭窗口
			}
			return true;
		}
	});
}

function delSort(_id, _this){
	if(_id < 10){
		$.jPops.alert({
			title:"提示",
			content:'对不起，该栏目不能删除！',
			okBtnTxt:"确定",
			callback:function(){
				return true;
			}
		});
		return false;
	}
	$.jPops.confirm({
		title:"提示",
		content:'您确定要删除这条数据吗？',
		okBtnTxt:"确定",
		cancelBtnTxt:"取消",
		callback:function(r){
			if(r){
				$.ajax({
					url: '/AcpArticleAjax/del_sort',
					data: {id: _id},
					dataType: 'json',
					success: function(data){
						if(data.status === 1){
							$(_this).parents('tr').fadeOut(400, function(){
								$(this).remove();
							});
						}
						$.jPops.alert({
							title:"提示",
							content:data.msg,
							okBtnTxt:"确定",
							callback:function(){
								return true;
							}
						});
					}
				});
			}
			return true;
		}
	});
}

function setUse(_id, _this){
	$.ajax({
		url: '/AcpArticleAjax/edit_cat_isuse',
		data: {id: _id},
		dataType: 'json',
		beforeSend: function(){
			$(_this).prev().removeClass('hide');
			$(_this).children().addClass('hide');
		},
		success: function(data){
			$(_this).prev().addClass('hide');
			if(data.isuse === 0){
				$(_this).children().attr('class', 'gicon-remove black')
			}else if(data.isuse === 1){
				$(_this).children().attr('class', 'gicon-ok black');
			}
		}
	});
}

function setSerial(_id, _this){
	var initVal = _this.defaultValue;
	var curVal = $(_this).val();
	if(curVal == ''){
		$(_this).val(initVal);
		return false;
	}
	if(curVal == initVal){
		return false;
	}
	$.ajax({
		url: '/AcpArticleAjax/edit_cat_serial',
		data: {id: _id, serial: curVal},
		dataType: 'json',
		beforeSend: function(){
			$(_this).prev().removeClass('hide');
			$(_this).addClass('hide');
		},
		success: function(data){
			$(_this).prev().addClass('hide');
			$(_this).removeClass('hide');
			if(data.status === 1){
				_this.defaultValue = curVal;
			} else {
				$(_this).val(initVal);
			}
			$.jPops.alert({
				title:"提示",
				content:data.msg,
				okBtnTxt:"确定",
				callback:function(){
					return true;
				}
			});
		}
	});
}
{/literal}
</script>
{/block} 

{block name="css"}
<link rel="stylesheet" href="/Public/Css/acp/AcpArticle/list_sort.css" type="text/css" />
{literal}
<style>
#jpops .fi-name{width:75px;}
#jpops .form-controls{margin-left:80px;}
.t-list{ float:left;}
</style>
{/literal}
{/block}
